package com.dhcc.core.framework.security.client.hos;

import com.dhcc.core.config.properties.SsoProperties;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.extractors.TokenExtractor;
import com.github.scribejava.core.model.OAuth2AccessToken;

public class HosApi extends DefaultApi20 {

    private String key;

    private String secret;

    /**
     * 授权码
     */
    private String code;

    public HosApi(String key, String secret) {
        setKey(key);
        setSecret(secret);
    }

    @Override
    public String getAccessTokenEndpoint() {
        String finialUrl = SsoProperties.me().getHosBackendUrl() +
                "/token" +
                "?client_id=" + key +
                "&client_secret=" + secret +
                "&grant_type=authorization_code";

        return finialUrl;
    }

    @Override
    protected String getAuthorizationBaseUrl() {
        return SsoProperties.me().getHosFrontUrl() + "/authorize";
    }

    @Override
    public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
        return HosJsonExtractor.instance();
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}


